using Godot;

public partial class CMoveState : CState
{
    public override void run(Node n, double delta)
    {
        if (n is NCharacter cha)
        {
            if (cha.HasInput)
            {
                if (cha.mLeftPressed)
                {
                    cha.mDir = DIR.LEFT;
                    cha.GlobalPosition += Vector2.Left * (float)delta * cha.mMoveSpeed;
                }
                if (cha.mRightPressed)
                {
                    cha.mDir = DIR.RIGHT;
                    cha.GlobalPosition += Vector2.Right * (float)delta * cha.mMoveSpeed;
                }
                if (cha.mUpPressed)
                {
                    cha.mDir = DIR.UP;
                    cha.GlobalPosition += Vector2.Up * (float)delta * cha.mMoveSpeed;
                }
                if (cha.mDownPressed)
                {
                    cha.mDir = DIR.DOWN;
                    cha.GlobalPosition += Vector2.Down * (float)delta * cha.mMoveSpeed;
                }
                cha.doAni(ANI.WALK);
            }
            else
            {
                cha.mState = new CIdleState();
                return;
            }
        }
    }
}